﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;

namespace ManagementTool.Managers
{
    public class ManagerControls
    {

        private void GetPcInfo() 
        {           
            //CPU
            ManagementClass mc = new ManagementClass("Win32_Processor");
            ManagementObjectCollection moc = mc.GetInstances();
            string strID = null;
            foreach (ManagementObject mo in moc)
            {
                strID = mo.Properties["ProcessorId"].Value.ToString() + "==CPU===";
                break;
            }

            //主板
            ManagementClass mc2 = new ManagementClass("Win32_BaseBoard");
            ManagementObjectCollection moc2 = mc2.GetInstances();

            foreach (ManagementObject mo in moc2)
            {
                strID += mo.Properties["SerialNumber"].Value.ToString();
                break;
            }

            //硬盘
            ManagementClass mc3 = new ManagementClass("Win32_PhysicalMedia");
            //网上有提到，用Win32_DiskDrive，但是用Win32_DiskDrive获得的硬盘信息中并不包含SerialNumber属性。   
            ManagementObjectCollection moc3 = mc3.GetInstances();
            foreach (ManagementObject mo in moc3)
            {
                strID += mo.Properties["SerialNumber"].Value.ToString();
                break;
            }
            //BIOS
            ManagementClass mc4 = new ManagementClass("Win32_BIOS");
            ManagementObjectCollection moc4 = mc.GetInstances();
            foreach (ManagementObject mo in moc4)
            {
                strID += mo.Properties["SerialNumber"].Value.ToString();
                break;
            }
        }

    }
}
